#include "get_int.h"
#include <cctype>
#include <stdexcept>
void skip_to_int(std::istream &is)
{
    if (is.fail())
    {
        is.clear();
        for (char ch; is >> ch;)
        {
            if (isdigit(ch) || ch == '-')
            {
                is.unget();
                return;
            }
        }
    }
    throw std::runtime_error("no input");
}

int get_int(std::istream &is)
{
    int n = 0;
    while (1)
    {
        if (is >> n)
            return n;
        std::cout << "Sorry,that was not a number;please try again\n";
        skip_to_int(is);
    }
}

int get_int(std::istream &is, int low, int high,
            const std::string &greeting, const std::string &sorry)
{
    std::cout << greeting << ": [" << low << ':' << high << "]\n";
    while (true)
    {
        int n = get_int(is);
        if (low <= n && n <= high)
            return n;
        std::cout << sorry << ": [" << low << ':' << high << "]\n";
    }
}